"""
文件名: WYL_MemberCollectionController.py
作用: 会员收藏管理接口
作者: 王亚丽
"""

from Untils.SendMethod import SendMethod
from Untils.GetKeyword import GetKeyword
from Interface.DHX_MemberInterface import MemberInterface


class MemberCollectionController:

    def __init__(self):
        self.url = 'http://139.159.146.104:8083'

    def collection_add_product(self, memberId, productId):
        """
        添加商品收藏
        :return:
        """
        mi = MemberInterface()
        headers = mi.get_token(username='liar', password='123456')
        payload = {
            'memberId': memberId,
            "productId": productId
        }
        url = self.url + '/member/collection/addProduct'
        return SendMethod.send_method(method='post', url=url, json=payload, headers=headers)

    def member_collection_deleteProduct(self,memberId, productId):
        """
        删除收藏商品
        """
        mi = MemberInterface()
        headers = mi.get_token(username='liar', password='123456')
        payload = {
            'memberId': memberId,
            'productId':productId
        }
        url = self.url + '/member/collection/deleteProduct'
        return SendMethod.send_method(method='post', url=url, data=payload, headers=headers)

    def member_collection_listProduct(self):
        """
        显示关注列表
        :return:
        """
        mi = MemberInterface()
        headers = mi.get_token(username='liar', password='123456')
        url = self.url + '/member/collection/listProduct/2'
        return SendMethod.send_method(method='get', url=url, headers=headers)


if __name__ == '__main__':
    mc = MemberCollectionController()
    # print(mc.collection_add_product('2', '1'))
    # print(mc.member_collection_deleteProduct('2','1'))
    print(mc.member_collection_listProduct())
